using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

namespace CrazyDogToDo.Entity.Data
{
    public partial class CrazyDogToDoContext : DbContext
    {
        public virtual DbSet<Activity> Activity { get; set; }
        public virtual DbSet<Inventory> Inventory { get; set; }
        public virtual DbSet<Matter> Matter { get; set; }
        public virtual DbSet<User> User { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            //#warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings.
            optionsBuilder.UseSqlServer(@"Data Source =BLGBBS-AARPB9HP\IRONY; Initial Catalog = CrazyDogToDo; User ID = sa; Password =IRONY.;MultipleActiveResultSets=true;");


        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Activity>(entity =>
            {
                entity.Property(e => e.Content).IsRequired();

                entity.Property(e => e.CreateTime).HasColumnType("datetime");

                entity.Property(e => e.Email)
                    .IsRequired()
                    .HasColumnType("varchar(50)");

                entity.Property(e => e.EndTime).HasColumnType("datetime");

                entity.Property(e => e.Theme)
                    .IsRequired()
                    .HasMaxLength(50);

                entity.HasOne(d => d.EmailNavigation)
                    .WithMany(p => p.Activity)
                    .HasForeignKey(d => d.Email)
                    .OnDelete(DeleteBehavior.Restrict)
                    .HasConstraintName("FK_Activity_User");
            });

            modelBuilder.Entity<Inventory>(entity =>
            {
                entity.Property(e => e.CreateTime).HasColumnType("datetime");

                entity.Property(e => e.Email)
                    .IsRequired()
                    .HasColumnType("varchar(50)");

                entity.Property(e => e.Title)
                    .IsRequired()
                    .HasMaxLength(50);

                entity.HasOne(d => d.EmailNavigation)
                    .WithMany(p => p.Inventory)
                    .HasForeignKey(d => d.Email)
                    .OnDelete(DeleteBehavior.Restrict)
                    .HasConstraintName("FK_Inventory_User");
            });

            modelBuilder.Entity<Matter>(entity =>
            {
                entity.Property(e => e.Content).IsRequired();

                entity.Property(e => e.CreateTime).HasColumnType("datetime");

                entity.Property(e => e.Email)
                    .IsRequired()
                    .HasColumnType("varchar(50)");

                entity.Property(e => e.OverdueTime).HasColumnType("datetime");

                entity.Property(e => e.Remark).HasMaxLength(50);

                entity.HasOne(d => d.EmailNavigation)
                    .WithMany(p => p.Matter)
                    .HasForeignKey(d => d.Email)
                    .OnDelete(DeleteBehavior.Restrict)
                    .HasConstraintName("FK_Matter_User");

                entity.HasOne(d => d.Inventory)
                    .WithMany(p => p.Matter)
                    .HasForeignKey(d => d.InventoryId)
                    .OnDelete(DeleteBehavior.Restrict)
                    .HasConstraintName("FK_Matter_Inventory");
            });

            modelBuilder.Entity<User>(entity =>
            {
                entity.HasKey(e => e.Email)
                    .HasName("PK_User");

                entity.Property(e => e.Email).HasColumnType("varchar(50)");

                entity.Property(e => e.NickName)
                    .IsRequired()
                    .HasMaxLength(50);

                entity.Property(e => e.Password)
                    .IsRequired()
                    .HasColumnType("varchar(50)");

                entity.Property(e => e.UserAvatar).HasColumnType("nvarchar(200)");
            });
        }
    }
}